package com.e2oto.seller.modules.seller.presenter;

import android.content.res.Resources;

import com.alibaba.fastjson.JSONObject;
import com.e2oto.seller.common.base.BasePresenter;
import com.e2oto.seller.modules.seller.bean.ProvinceBean;
import com.e2oto.seller.modules.seller.views.SelectAddressView;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

/**
 * Created by ZhangLiQiang on 2017/11/14.
 */

public class SelectAddressPresenter extends BasePresenter<SelectAddressView> {

    public void getAddress(Resources resources) {
        InputStreamReader inputStreamReader;
        try {
            inputStreamReader = new InputStreamReader(resources.getAssets().open("area.json"), "UTF-8");
            BufferedReader bufferedReader = new BufferedReader(
                    inputStreamReader);
            String line;
            StringBuilder stringBuilder = new StringBuilder();
            while ((line = bufferedReader.readLine()) != null) {
                stringBuilder.append(line);
            }
            inputStreamReader.close();
            bufferedReader.close();
            getView().getAddressCallback( JSONObject.parseArray(stringBuilder.toString(), ProvinceBean.class));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
